package Exceptions.test3;

import java.util.Scanner;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/27
 */
public class ExceptionTest {
    private String id;
    private double balance;

    public boolean withdraw(double amount)throws BalanceNotEnoughException {
        if (balance >= amount) {
            balance -= amount;
            return true;
        }else{
            throw new BalanceNotEnoughException("您的余额不足！");
        }


    }

    public ExceptionTest() {
    }

    public ExceptionTest(String id, double balance) {
        this.id = id;
        this.balance = balance;
    }

    /**
     * 获取
     * @return id
     */
    public String getId() {
        return id;
    }

    /**
     * 设置
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * 获取
     * @return balance
     */
    public double getBalance() {
        return balance;
    }

    /**
     * 设置
     * @param balance
     */
    public void setBalance(double balance) {
        this.balance = balance;
    }

    public String toString() {
        return "ExceptionTest{id = " + id + ", balance = " + balance + "}";
    }

    public static void main(String[] args) {
        ExceptionTest ex = new ExceptionTest("111",10000);
        System.out.println("请输入取款金额：");
        Scanner sc = new Scanner(System.in);
        try {
            double amount = sc.nextDouble();
            ex.withdraw(amount);
        } catch (BalanceNotEnoughException e) {
            e.printStackTrace();
        }finally {
            System.out.println("您的余额还剩"+ex.getBalance());
        }

    }
}
